package objects;

import java.util.Random;

import materials.Material;
import math.Vector3D;
import render.Ray;
import render.TraceResult;

public class Maze extends Plane {

    private int[][] data = new int[100][100];

    public Maze( Vector3D position , Vector3D normal , Material material ) {
	super( position, normal, material );
	Random r = new Random();
	for ( int x = 0; x < 100; x++ ) {
	    for ( int y = 0; y < 100; y++ ) {
		data[x][y] = x % 2 + y % 2;
	    }
	}
    }

    public TraceResult trace( Ray ray ) {
	TraceResult trace = super.trace( ray );

	Vector3D hitpos = ray.getPosition().add( ray.getDirection().mult( trace.getDistance() ) );

	int x = (int) ((int) (hitpos.getX() / 100) - position.getX());
	int z = (int) ((int) (hitpos.getZ() / 100) - position.getZ());

	if ( !((x < 0 || x >= 100) || (z < 0 || z >= 100)) ) {
	    if ( data[x][z] >= 1 )
		return trace;
	}
	return new TraceResult( false , 0 );
    }
}
